package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.logistic.domain.NetworkSheetPriceSalesman;
import com.ruoyi.logistic.domain.NetworkSheetPriceSalesmanRecord;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkSheetPriceSalesmanVo;
import com.ruoyi.logistic.mapper.NetworkSheetPriceSalesmanMapper;
import com.ruoyi.logistic.mapper.NetworkSheetPriceSalesmanRecordMapper;
import com.ruoyi.logistic.service.NetworkSheetPriceSalesmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;
@Service
public class NetworkSheetPriceSalesmanServiceImpl implements NetworkSheetPriceSalesmanService {
    @Autowired
    private NetworkSheetPriceSalesmanMapper networkSheetPriceSalesmanMapper;
    @Autowired
    private NetworkSheetPriceSalesmanRecordMapper networkSheetPriceSalesmanRecordMapper;
    @Override
    public List<NetworkSheetPriceSalesman> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkSheetPriceSalesmanMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkSheetPriceSalesman networkSheetPriceSalesman) {
        return networkSheetPriceSalesmanMapper.insert(networkSheetPriceSalesman);
    }

    @Override
    public Boolean update(NetworkSheetPriceSalesman networkSheetPriceSalesman) {
        NetworkSheetPriceSalesmanRecord record = new NetworkSheetPriceSalesmanRecord();
        record.setContent(networkSheetPriceSalesman.getSheetFee()+"");
        record.setSalesmanId(networkSheetPriceSalesman.getId());
        record.setUpdateBy(SecurityUtils.getUserId());
        networkSheetPriceSalesmanRecordMapper.insert(record);
        return networkSheetPriceSalesmanMapper.update(networkSheetPriceSalesman);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkSheetPriceSalesmanMapper.deleteById(id);
    }

    @Override
    public NetworkSheetPriceSalesman findById(Integer id) {
        return networkSheetPriceSalesmanMapper.findById(id);
    }

    @Override
    public List<NetworkSheetPriceSalesman> search(NetworkSheetPriceSalesmanVo networkSheetPriceSalesmanVo) {
        PageHelper.startPage(networkSheetPriceSalesmanVo.getPageDate());
        return networkSheetPriceSalesmanMapper.search(networkSheetPriceSalesmanVo);
    }

    @Override
    public List<NetworkSheetPriceSalesmanRecord> searchDetail(Date startTime, Date endTime, Integer id) {
        return networkSheetPriceSalesmanRecordMapper.search(startTime,endTime,id);
    }
}
